Skip to content

Fix AddDependency no-op when libs.versions.toml is present on Gradle 9#7550

Open
timtebeek wants to merge 5 commits intomainfrom
tim/issue-7548
Open

Fix AddDependency no-op when libs.versions.toml is present on Gradle 9#7550
timtebeek wants to merge 5 commits intomainfrom
tim/issue-7548

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 3, 2026

Summary

  • Fixes AddDependency no-op against build.gradle.kts when libs.versions.toml is present, on Gradle 9.x daemon (works on Gradle 8.x) #7548. The withToolingApi test helper was mutating projectDir to the gradle/ subdirectory whenever a gradle/libs.versions.toml source file was provided; on Gradle 8.x the -b flag masked the bug, but on Gradle 9.x (which dropped -b) the daemon evaluated the wrong directory, returned a GradleProject with empty nameToConfiguration, and AddDependency silently no-opped. The mutation is removed, AddDependencyVisitor now emits a Markup.warn listing available configurations instead of silently swallowing unknown-configuration cases, and a regression test exercises the catalog scenario on both Gradle 9.0.0 and 8.14.3.

Test plan

  • New AddDependencyGradle9CatalogTest passes on Gradle 9.0.0 and Gradle 8.14.3
  • :rewrite-gradle:test (full module sweep) passes

The `withToolingApi` test helper was mutating `projectDir` to the
`gradle/` subdirectory whenever it saw a `gradle/libs.versions.toml`
source file. On Gradle 8.x the `-b` flag still pointed the daemon at
the real build script, masking the bug; on Gradle 9.x the flag was
removed and the daemon evaluated the wrong directory, returning a
GradleProject whose `nameToConfiguration` was empty. AddDependency
then silently no-opped because `getConfiguration("compileOnly")`
returned null.

- Drop the projectDir mutation: `gradle/libs.versions.toml` is a
  catalog inside the existing project, not a project-root marker.
- AddDependencyVisitor now emits a `Markup.warn` listing available
  configurations instead of silently swallowing unknown-configuration
  cases, so future shape mismatches surface.
- Add AddDependencyGradle9CatalogTest covering Gradle 9.0.0 and 8.14.3
  with the catalog present.

Fixes #7548
timtebeek added 4 commits May 3, 2026 14:29
OpenRewrite's MavenPomDownloader was getting an HTTP 404 for
lombok 1.18.44 in CI, even though the artifact exists. Use a
long-stable version to avoid transient resolution flakes.
CI runners are intermittently getting HTTP 404 from Maven Central
for stable artifacts (also affects main). Pass version=null so
AddDependency does not invoke MavenPomDownloader. The bug under
test is about the recipe making no change at all when
libs.versions.toml is present on Gradle 9, so the dependency
version is incidental.
@timtebeek timtebeek requested a review from shanman190 May 4, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

AddDependency no-op against build.gradle.kts when libs.versions.toml is present, on Gradle 9.x daemon (works on Gradle 8.x)

1 participant